/* Conversations (Reamaze) widget β€” AppImpl loader */ (function () { var COOKIE_NAME = "cookie_terms_accepted"; var pollTimer = null; var scriptEl = null; function hasCookieConsent() { return document.cookie.indexOf(COOKIE_NAME + "=") !== -1; } function loadReamazeScript(src) { if (typeof Reamaze !== "undefined" || scriptEl) return; scriptEl = document.createElement("script"); scriptEl.type = "text/javascript"; scriptEl.async = true; scriptEl.defer = true; scriptEl.src = src; var first = document.getElementsByTagName("script")[0]; if (first && first.parentNode) { first.parentNode.insertBefore(scriptEl, first); } else { (document.head || document.body).appendChild(scriptEl); } } function waitForConsentThenLoad(src) { if (pollTimer) { clearInterval(pollTimer); pollTimer = null; } if (hasCookieConsent()) { loadReamazeScript(src); return; } pollTimer = setInterval(function () { if (hasCookieConsent()) { clearInterval(pollTimer); pollTimer = null; loadReamazeScript(src); } }, 1000); } function buildSupportConfig(settings, siteId) { var label = { text: settings["chat.prompt"] || "Let us know if you have any questions! 😊", mode: "notification", delay: 3, duration: 30, sound: true, }; // Conversation starters β†’ label.primary, primary2–primary5 if (settings["chat.starter1"]) label.primary = settings["chat.starter1"]; if (settings["chat.starter2"]) label.primary2 = settings["chat.starter2"]; if (settings["chat.starter3"]) label.primary3 = settings["chat.starter3"]; if (settings["chat.starter4"]) label.primary4 = settings["chat.starter4"]; if (settings["chat.starter5"]) label.primary5 = settings["chat.starter5"]; // Dismiss label β†’ label.secondary if (settings["chat.dismiss"]) label.secondary = settings["chat.dismiss"]; var config = { account: siteId, ui: { contactMode: "mixed", enableKb: "true", styles: { widgetColor: settings["chat.widgetColor"] || "#111827", gradient: true, }, shoutboxFacesMode: "custom", widget: { icon: "webChat", delay: 10, allowBotProcessing: settings["chat.enableChatbots"] === false ? "false" : "true", label: label, position: (settings["chat.position"] || "bottom-right") === "bottom-right" ? { bottom: "35px", right: "22px" } : settings["chat.position"], }, overrides: {}, apps: { recentConversations: {}, faq: { enabled: true }, }, }, user: { authpath: "/m/api/reamaze/v2/customers/auth?brand=" + siteId, }, }; // Confirmation message (auto-reply) if (settings["chat.confirmationMessage"]) { config.ui.overrides.confirmationMessage = settings["chat.confirmationMessage"]; } return config; } window.GDApps.register("conversations", { mount: function (ctx) { var settings = ctx.config.settings || {}; var context = ctx.config.context || {}; var siteId = context.siteId; // If chat is explicitly disabled, tear down any existing widget and bail if (settings["chat.enabled"] === false) { if (pollTimer) { clearInterval(pollTimer); pollTimer = null; } if (window._support && window._support.ui) { window._support.ui.widget = false; } if (typeof Reamaze !== "undefined") { Reamaze.reload(); } return; } // Must have a siteId to function if (!siteId) return; var mode = context.mode || "live"; var isEditor = mode === "edit" || mode === "preview"; // In editor, cookie banner must be enabled β€” tear down if it was removed if (isEditor && !context.hasCookieBanner) { if (pollTimer) { clearInterval(pollTimer); pollTimer = null; } if (window._support && window._support.ui) { window._support.ui.widget = false; } if (typeof Reamaze !== "undefined") { Reamaze.reload(); } return; } var cdnDomain = settings["chat.cdnDomain"] || "cdn.reamaze.com"; var reamazeSrc = "https://" + cdnDomain + "/assets/reamaze.js"; window._support = buildSupportConfig(settings, siteId); // Mount the widget inside the app container so it lives within the // editor content area rather than at the document root. if (ctx.container) { window._support.ui.widget.mountTarget = ctx.container; window._support.ui.widget.mountPosition = isEditor ? 'absolute' : 'fixed'; } if (isEditor) { window._support._preview = true; window._support.ui.widget.label = false; } // If Reamaze was already loaded (re-mount after settings change), reload it // with the updated _support config. On initial load Reamaze is undefined so // this is a no-op β€” no double flash. if (typeof Reamaze !== "undefined") { Reamaze.reload(); return; } if (isEditor) { loadReamazeScript(reamazeSrc); } else { waitForConsentThenLoad(reamazeSrc); } }, unmount: function () { if (pollTimer) { clearInterval(pollTimer); pollTimer = null; } // Signal Reamaze to shut down before removing its DOM if (typeof Reamaze !== "undefined" && window._support && window._support.ui) { window._support.ui.widget = false; Reamaze.reload(); } if (scriptEl && scriptEl.parentNode) { scriptEl.parentNode.removeChild(scriptEl); scriptEl = null; } var container = document.getElementById("reamazejs-container"); if (container) container.parentNode.removeChild(container); try { delete window._support; } catch (e) { window._support = undefined; } }, }); })();